﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Shapes;
using System.Xml;

using KELT;

namespace KELT.KELTObjects.ViewportObjectModel
{

    public class RectangleObject : ViewportObj
    {
        private Rectangle frontRectangleObject;
        private Rectangle backRectangleObject;

        public RectangleObject(TOOL mainContext, double x, double y)
        {
            ObjectInfo = "RectangleObject";
            double changeX = (x * 2 / mainContext.mainViewport.RenderSize.Width - 1) * (0.4 * mainContext.cameraManager.getPoint3D().Z) + mainContext.cameraManager.getPoint3D().X + mainContext.cameraManager.getTranslateTransform().OffsetX;
            double changeY = (y * -2 / mainContext.mainViewport.RenderSize.Height + 1) * (0.24 * mainContext.cameraManager.getPoint3D().Z) + mainContext.cameraManager.getPoint3D().Y + mainContext.cameraManager.getTranslateTransform().OffsetY;

            indexNumber = mainContext.viewPortMgr.INDEXNUMBER;
            objectName = "object" + indexNumber;

            frontRectangleObject = new Rectangle();
            backRectangleObject = new Rectangle();

            point = new Point3D(changeX, changeY, 0);

            frontViewBox = new Viewbox();
            frontViewBox.Name = ObjectInfo + indexNumber;

            FrontViusal = new Viewport2DVisual3D();




            colorBrush = new SolidColorBrush();

            frontRectangleObject.Width = 100;
            frontRectangleObject.Height = 100;
            colorBrush.Color = Brushes.Red.Color;
            frontRectangleObject.Stroke = new SolidColorBrush(Brushes.Red.Color);

            frontRectangleObject.Fill = colorBrush;
            frontViewBox.Child = frontRectangleObject;

            FrontViusal = CreateFront(frontViewBox, FrontTransform3DGroup);


            CreateBack(mainContext);


            BackViewBox.Child = backRectangleObject;


            frontViewBox.MouseDown += new MouseButtonEventHandler(mainContext.Object_MouseDown);
            frontViewBox.MouseMove += new MouseEventHandler(mainContext.Object_MouseMove);

            isVisual = true;
            mainContext.mainViewport.Children.Add(FrontViusal);

            mainContext.RegisterName(AnimationInfo.ANIMATION_ALPHA + indexNumber, colorBrush);
            mainContext.RegisterName(AnimationInfo.ANIMATION_TRANSLATE + indexNumber, FrontTransform3DGroup.Children.ElementAt(0));
            mainContext.RegisterName(AnimationInfo.ANIMATION_SCALE + indexNumber, FrontTransform3DGroup.Children.ElementAt(1));
            mainContext.RegisterName(AnimationInfo.ANIMATION_ROTATE + indexNumber, FrontTransform3DGroup.Children.ElementAt(2));


        }

        #region XML
        public override void GetObjInfoXML(XmlWriter writer)
        {
            writer.WriteStartElement("RectangleObject");
            {
                //writer.WriteElementString("fileSource", );
            }
            writer.WriteEndElement();
        }
        #endregion
    }
}
